package cn.wikiflyer.beikang.utils.task;

import java.lang.reflect.Type;

import android.content.Context;
import cn.wikiflyer.beikang.IApplication;
import cn.wikiflyer.beikang.bean.base.BKBaseBean;
import cn.wk.libs4a.net.WKAsyncTaskPro;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * 申请验证码，尝试把相对独立的Task单独拿出来
 */
public class GetVerifyCodeTask extends WKAsyncTaskPro {
	private String mobile;
	private Context ctx;

	public GetVerifyCodeTask(Context context, String mobile) {
		super(context);
		this.ctx = context;
		this.mobile = mobile;
	}

	private IApplication app() {
		return (IApplication) this.ctx.getApplicationContext();
	}

	@Override
	protected String doInBackground(boolean... params) {
		return app().net.send_verify(mobile, false);
	}

	@Override
	protected void doOnPostExecute(String result, boolean isLocal) {
		Type cvbType = new TypeToken<BKBaseBean>() {
		}.getType();
		Gson gson = new Gson();
		BKBaseBean base = gson.fromJson(result, cvbType);
		if (base.status == 1) {
			IApplication.showToast("验证码发送成功");
		} else {
			IApplication.showToast(base.info);
		}
	}
}